package com.hjm.friend.controller.user;

import com.hjm.api.domain.UserQuestionResultVO;
import com.hjm.common.core.controller.BaseController;
import com.hjm.common.core.domain.Result;
import com.hjm.friend.annotation.CheckUserStatus;
import com.hjm.friend.domain.user.dto.UserSubmitDTO;
import com.hjm.friend.service.user.UserSubmitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/user/question")
public class UserQuestionController extends BaseController {

    @Autowired
    UserSubmitService userSubmitService;


    @PostMapping("/submit")
    public Result<UserQuestionResultVO> submit(@RequestBody UserSubmitDTO userSubmitDTO) {
        return userSubmitService.submit(userSubmitDTO);
    }

    // 当数据量较大时，某一瞬间的请求可能需要很长时间
    // 这里 我们使用 rabbitmq 来进行 削峰
    @CheckUserStatus
    @PostMapping("/rabbit/submit")
    public Result<Void> rabbitSubmit(@RequestBody UserSubmitDTO userSubmitDTO) {
        return toResult(userSubmitService.rabbitSubmit(userSubmitDTO));
    }

    @CheckUserStatus
    @GetMapping("/exe/result")
    public Result<UserQuestionResultVO> exeResult(Long examId, Long questionId,String currentTime) {
        return Result.ok(userSubmitService.exeResult(examId, questionId,currentTime));
    }

}
